package com.mumu.poi.excel;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

/**
 * @author mumu
 * @version 1.0
 * @date 2024/1/8 15:44
 * @describe
 */
public class BaseGenerate {
    public static void main(String[] args) throws IOException {
        //文件路径
        String filePath = "excel/BaseGenerate.xls";
        //创建Excel文件(Workbook)
        HSSFWorkbook workbook = new HSSFWorkbook();
        //创建工作表(Sheet)
        HSSFSheet sheet = workbook.createSheet("Test");
        // 创建行,从0开始
        HSSFRow row = sheet.createRow(0);
        // 创建行的单元格,也是从0开始
        HSSFCell cell = row.createCell(0);
        // 设置单元格内容
        cell.setCellValue("CsdnerM");
        // 设置单元格内容,重载
        row.createCell(1).setCellValue(false);
        // 设置单元格内容,重载
        row.createCell(2).setCellValue(new Date());
        // 设置单元格内容,重载
        row.createCell(3).setCellValue(12.345);

        FileOutputStream out = new FileOutputStream(filePath);
        //保存Excel文件
        workbook.write(out);

        out.close();//关闭文件流
        System.out.println("OK!");

    }
}
